<template>
  <div>
    <div>
      <h2>今天是{{ $store.state.day }}</h2>
      <!-- <button @click="displayTime">显示时间</button> -->
      <h2>{{ time }}</h2>
      <p>--------------------------------------</p>
      <button @click="addition">+</button>
      <button @click="subtraction">-</button>
      <h2>{{ $store.state.counter }}</h2>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      time: "",
    };
  },
  mounted(){
      this.displayTime();
  },
  methods: {
    displayTime() {
      console.log(this.$store.state.time);
      this.time = this.$store.state.time;
      this.$store.commit("updateTime")
      setTimeout(()=>{
          this.displayTime();
      },1000)
    },
    addition() {
      this.$store.commit("add");
    },
    subtraction() {
      this.$store.commit("sub");
    },
  },
};
</script>
